 package org.csu.mybigpro.controller;

 import jakarta.validation.Valid;
 import jakarta.validation.constraints.NotBlank;
 import lombok.Data;
 import org.csu.mybigpro.common.CommonResponse;
 import org.csu.mybigpro.service.AuthService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;

 import java.util.Map;

 @RestController
 @RequestMapping("/api/teacher/auth") // 为所有接口设置统一的前缀
 @Validated
 public class TeacherAuthController {

     @Autowired
     private AuthService authService;

     // 创建一个静态内部类来接收请求体，使代码更清晰
     @Data
     static class LoginRequest {
         @NotBlank(message = "用户名不能为空")
         private String username;
         @NotBlank(message = "密码不能为空")
         private String password;

     }

     @PostMapping("/login")
     public CommonResponse<Map<String, Object>> login(@Valid @RequestBody LoginRequest loginRequest) {
         System.out.println(loginRequest.username);
         return authService.login(loginRequest.getUsername(), loginRequest.getPassword());
     }
 }